
const { ccclass, property } = cc._decorator;
/** 复杂聊天 聊天界面 加载聊天数据中 create by tm */
@ccclass
export default class DWC_DCLoading extends cc.Component {

    //-----------组件区----------
    /** 加载中 */
    @property(cc.Label)
    lbl_loading: cc.Label = null;
    //-----------变量区----------
    /** 加载timer */
    loadtimer: number = null;
    /** 加载中txt */
    loadArr: string[] = null;
    onLoad() {
        this.loadArr = [`加载中`, `加载中.`, `加载中..`, `加载中...`];
    }
    /** 开始加载 
     * @param 加载间隔时间(单位毫秒)
    */
    startLoad(_spacet: number = 200): void {
        this.loadtimer && clearInterval(this.loadtimer);
        let _loadIdx: number = 0;
        this.lbl_loading.string = this.loadArr[_loadIdx];
        this.loadtimer = setInterval(() => {
            _loadIdx >= this.loadArr.length - 1 ? _loadIdx = 0 : _loadIdx++;
            this.lbl_loading.string = this.loadArr[_loadIdx];
        }, _spacet);
    }
    /** 结束加载 */
    endLoad(): void {
        this.loadtimer && clearInterval(this.loadtimer);
        this.node.destroy();
    }
    onDestroy() {
        this.loadtimer && clearInterval(this.loadtimer);
    }
}
